package com.spice.service.entity.job;

import cn.hutool.core.io.FileUtil;
import com.alibaba.fastjson.JSON;
import lombok.Getter;

import java.io.File;
@Getter
public class SaveRecordJob extends Job {


    public static File historyJobFolder = new File("resources/historyJob/");


    public SaveRecordJob() {
        super.setPriority(1);
    }

    @Override
    protected Boolean runMethod() throws Exception {
        JobExecutor.doneJobList.removeIf(job -> {
            try {
                String jsonString = JSON.toJSONString(job);
                FileUtil.writeUtf8String(jsonString, new File(historyJobFolder, job.id));
                return true;
            } catch (Exception e) {
                e.printStackTrace();
                return false;
            }
        });
        return false;
    }

}
